package cn.xianshu.pay.controller;

import cn.xianshu.basic.exception.BasicException;
import cn.xianshu.basic.util.AxiosResult;
import cn.xianshu.pay.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pay")
public class PayController {


    @Autowired
    private IPayService payService;


    @PostMapping("/applyPay/{orderNo}")
    public AxiosResult applyPay(@PathVariable("orderNo") String orderNo){
        try {
            String htmlResult = payService.applyPay(orderNo);
            return AxiosResult.me().setResultObj(htmlResult);
        } catch (BasicException e) {
            e.printStackTrace();
            return AxiosResult.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AxiosResult.me().setMessage("系统异常!");
        }
    }
}
